﻿using BusinessLogic.Caching;
using BusinessLogic.Data;
using BusinessLogic.Messages;
using BusinessLogic.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;

namespace BusinessLogic.Customer
{
    public partial class CompanyService : ICompanyService
    {
        #region Fields

        /// <summary>
        /// Object context
        /// </summary>
        private readonly DataMailDataContext _context;
        /// <summary>
        /// Cache manager
        /// </summary>
        private readonly ICacheManager _cacheManager;

        #endregion

        #region Ctor

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="context">Object context</param>
        public CompanyService(DataMailDataContext context)
        {
            this._context = context;
            this._cacheManager = new PayrollRequestCache();
        }

        #endregion
        public EmailAccount GetAccount(int companyid, int option)
        {
            var query = (from mc in _context.MyCompanies
                         where mc.MyCompanyID == companyid
                         select mc).FirstOrDefault();
            EmailAccount emailaccount = new EmailAccount
            {
                DisplayName = query.Name,
                Email = query.Receive,
                EnableSSL = true,
                Host = query.Host,
                Port = query.Port.Value,
                Password = SecurityHelper.Decrypt(query.EmailPassword),
                Username = (from c in query.Receive.Split('@') select c).FirstOrDefault()
            };
            return emailaccount;
        }
    }
}
